<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/pages/common/taglib.jsp" %>
<div class="container-fluid am-margin">
    <form id="menuForm">
        <input type="hidden" name="id"/>
        <input type="hidden" name="pid"/>
        <input type="hidden" name="funcPointId"/>
        <input type="hidden" name="sysFlag"/>
        <input type="hidden" name="seqNum">
        <div class="form-group">
            <label for="name">菜单名</label>
            <input type="text" name="name" class="form-control" >
        </div>
        <div class="form-group">
            <label for="code">编码</label>
            <input type="text" name="code" class="form-control" >
        </div>
        <div class="form-group">
            <label for="iconCss">图标(class)</label>
            <input type="text" name="iconCss" class="form-control" >
        </div>
        <div class="form-group">
            <label for="iconPath">图标路径</label>
            <input type="text" name="iconPath" class="form-control" >
        </div>
        <div class="form-group">
            <label for="funcPointId">功能点</label>
            <input type="text" name="funcPoint.name" class="form-control" >

        </div>
        <div class="form-group">
            <label for="funcPointId">URL</label>
            <span type="text" name="funcPoint.url" class="form-control" ></span>
            <div>
                <a id="cleanFuncPointBt" href="javascript:void(0)">清空</a>
            </div>
        </div>
        <div class="form-group">
            <label for="openType">打开方式</label>
            <select class="form-control"  name="openType">
                <option value=""> </option>
                <pf:dataDic var="item" dicCode="MENU_OPEN_TYPE">
                    <option value="${item.value}">${item.name}</option>
                </pf:dataDic>
            </select>
        </div>
        <shiro:hasPermission name="MENU_ADD">
        <shiro:hasPermission name="MENU_MOD">
        <div class="form-group">
            <a href="javascript:void(0)" id="menuSaveBt"  class="btn btn-primary">保存</a>
        </div>
        </shiro:hasPermission>
        </shiro:hasPermission>
    </form>
</div>
<script type="text/javascript">
    $(function () {
        var menuForm = $("#menuForm");
        var pid = '${param.pid}';
        var id = '${param.id}';
        var sysFlag = '${param.sysFlag}';

        menuForm.find("input[name=pid]").val(pid);
        menuForm.find("input[name=sysFlag]").val(sysFlag);

        if (id) {
            $.getJSON(ctx + '/menuAction/getMenu.do', {id: id}, function (data) {
                webUtils.fullForm({
                    form: menuForm,
                    data: data
                });
            });
        }
        $("#menuSaveBt").click(function () {
            menuForm.ajaxSubmit({
                url: ctx + '/menuAction/saveMenu.do',
                data: {},
                type: "POST",
                success: function (data) {
                    if (data.success) {
                        webUtils.alert("提交成功");
                        top.webUtils.topicPublish("menu.edit.success", data);
                    } else {
                    	webUtils.error(data.msg);
                    }
                }
            });
        });

        $("#cleanFuncPointBt").click(function () {
            menuForm.find("input[name='funcPoint.name']").val("");
            menuForm.find("span[name='funcPoint.url']").html("");
            menuForm.find("input[name=funcPointId]").val("");
        });

        menuForm.find("input[name='funcPoint.name']").click(function () {
            var sub = top.webUtils.topicSubscribe("funcPointForMenu.selected", function (data) {
                menuForm.find("input[name='funcPoint.name']").val(data.name);
                menuForm.find("span[name='funcPoint.url']").html(data.url);
                menuForm.find("input[name=funcPointId]").val(data.id);
                dialog.close();
                
                initMenuName(data.name);
            });
            
            var dialog=webUtils.dialog({
              	 title:'关联功能点',
              	 url:ctx + '/funcPointAction/listForMenuView.do',
              	 onremove:function () {
              		sub.remove();
                   }
               });
        });
        
        function initMenuName(functionName){
             var name=menuForm.find("input[name='name']").val();
             if(!name){
                 menuForm.find("input[name='name']").val(functionName.substring(functionName.lastIndexOf("-")+1),functionName.length);
             }
        }
    });
</script>